package com.ojoin.trade.t0loan_core.web.service;

import java.util.List;

import org.springframework.data.domain.Pageable;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.web.service.BaseService;
import com.ojoin.trade.t0loan_core.web.domain.T0LoanLiveUserHistoryTransTotalInfoVO;
import com.ojoin.trade.t0loan_core.web.domain.TbT0LoanLiveApplication;
import com.ojoin.trade.t0loan_core.web.domain.TbT0LoanLiveInfoVO;
import com.ojoin.trade.t0loan_core.web.domain.TbT0LoanTodoTaskVO;

/**
 * T+0贷款申请服务接口
 * @author guoting
 *
 */
public interface T0LoanLiveBaseService extends BaseService<TbT0LoanLiveApplication> {
	
	/**
	 * 新增T+0贷款申请记录(T0000001)
	 * @param joinuserNo
	 * 
	 * 说明：向tb_t0_loan_live_application表插入一条记录，记录业务日志
	 * 
	 * @throws BusinessException
	 */
	public int insertT0LoanLiveInfo(int joinuserNo) throws BusinessException;
	
	/**
	 * 新增T+1贷款申请记录(T0000001)
	 * @param joinuserNo
	 * 
	 * 说明：向tb_t0_loan_live_application表插入一条记录，记录业务日志
	 * 
	 * @throws BusinessException
	 */
	public int insertTxLoanLiveInfo(int joinuserNo, String operatetype) throws BusinessException;
	
	/**
	 * 根据九盈用户id查询用户的T+0贷款申请记录(T0000002)
	 * @param joinuserNo
	 * 
	 * 说明：查询tb_t0_loan_live_application表中id_of_tb_merchant_user为传入参数值的记录，记录业务日志
	 * 
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanLiveApplication> queryT0LoanLiveInfoByJoinUserID(int joinuserNo) throws BusinessException;
	
	/**
	 * 根据九盈用户id查询用户的T+1贷款申请记录
	 * @param joinuserNo
	 * 
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanLiveApplication> queryT1LoanLiveInfoByJoinUserID(int joinuserNo) throws BusinessException;
	
	/**
	 * 查询指定贷款状态的所有九盈用户T+0贷款业务申请记录 (T0000003)
	 * @param loanlivestatus
	 * 
	 * 说明：查询tb_t0_loan_live_application表中status为传入参数值的记录，记录业务日志
	 * 
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanLiveInfoVO> queryAllT0LoanLiveInfoByStatus(Integer loanstatus, Pageable page) throws BusinessException;
	
	/**
	 * 查询指定贷款状态的所有九盈用户Tx贷款业务申请记录
	 * 
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanLiveInfoVO> queryAllTxLoanLiveInfoByApplying(Pageable page, String operatetype) throws BusinessException;
	
	/**
	 * 修改指定记录的T+0贷款申请状态(T0000004)
	 * @param liveids
	 * @param loanlivestatus
	 * 
	 * 说明：修改tb_t0_loan_live_application表中id为传入参数值的记录的
	 * 申请状态status为传入的status参数值，记录业务日志
	 * 
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoByLiveIDsAndStatus(int[] liveids, int loanlivestatus) throws BusinessException;
	
	
	public int updateTxLoanLiveInfoByLiveIDsAndStatus(String operatetype, int[] liveids, int idOfTbMerchantUserOfCreditor,
			int loanstatus) throws BusinessException;
	/**
	 * 根据九盈用户id查询用户的最近一次T+0贷款申请记录(T0000025)
	 * @param joinuserid
	 * @return
	 * @throws BusinessException
	 */
	public TbT0LoanLiveApplication queryNewlyT0LoanLiveInfoByJoinUserID(
			int joinuserid) throws BusinessException;
	
	/**
	 * 根据九盈用户id查询用户的最近一次T+1贷款申请记录
	 * @param joinuserid
	 * @param operatetype
	 * @return
	 * @throws BusinessException
	 */
	public TbT0LoanLiveApplication queryNewlyTxLoanLiveInfoByJoinUserID(
			int joinuserid, String operatetype) throws BusinessException;
	
	
	/**
	 * 查询申请T+0贷款审核通过的九盈用户的当日前30日历史交易金额合计列表(T0000027)
	 * @return
	 * @throws BusinessException
	 */
	public List<T0LoanLiveUserHistoryTransTotalInfoVO> queryT0LoanLiveUserHistoryTransTotalInfoList(Pageable page) 
			throws BusinessException;
	
	//////////////////////////
	/**
	 * 审核用户T+0业务申请不通过，提交不通过原因并更新状态为-1
	 * @param liveid
	 * @param memo
	 * @return
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoApplyNoPassByLiveID(int liveid,
			String memo) throws BusinessException;
			
	/**
	 * 修改T+0贷款申请记录的设定手续费和利率，并更新状态为2 (T0000034)
	 * @param liveid
	 * 
	 * 说明：修改tb_t0_loan_live_application表中liveid为传入参数值的记录的
	 * 申请状态status为2，fee/ratio/expected_loan_time为传入参数，记录业务日志
	 * 
	 * used in AdminUserController
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoFeeAndRatioByLiveID(int liveid, String fee, 
			String ratio, String expected_loan_time, int creditorid) throws BusinessException;
	
	/**
	 * 修改T+0贷款申请记录的授信额度、生成相关文件，并更新状态为3 (T0000035)
	 * 
	 * 说明：
	 * 1)、调用金融账户开户(JA000012)
	 * 2)、生成保理合同pdf文件，填充相关内容
	 * 3)、生成账户变更申请表文件，填充相关内容
	 * 4)、更新授信额度及保理合同、账户变更申请表文件路径及状态为3
	 * 
	 * @param liveid
	 * @param joinuserid
	 * @param rm_daily_threshold
	 * @param rm_single_threshold
	 * @param qryprintscreen
	 * 
	 * used in OperatorUserController
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoLimitByLiveID(int liveid, int joinuserid, String rm_daily_threshold,
			String rm_single_threshold,String qryprintscreen, String filePath) throws BusinessException;

	/**
	 * 查询指定九盈用户申请T+0贷款记录状态为3的信息，获取生成的保理合同和账户变更申请表(T0000036)
	 * @param joinuserid
	 * 
	 * @return
	 * String[0] 保理合同
	 * String[1] 账户变更申请表
	 * 
	 * used in T0LoanLiveApplicationController
	 * @throws BusinessException
	 */
	public String[] queryT0LoanLiveContractFileByJoinuserid(int joinuserid) throws BusinessException;
	
	/**
	 * 上传用户盖章后的账户变更申请表，修改T+0贷款申请记录的状态为4 (T0000037)
	 * @param liveid
	 * @param userchangefilepath
	 * 
	 * used in T0LoanLiveApplicationController
	 * @throws BusinessException
	 */
	public int uploadT0LoanUserCommitFileByLiveID(int liveid, String userchangefilepath) throws BusinessException;

	/**
	 * 更新T+0贷款申请记录的状态为5(账户变更申请表审核通过) (T0000038)
	 * 
	 * used in OperatorUserController
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoUserCommitPass(int liveid) throws BusinessException;
	
	/**
	 * 审核用户提交的账户变更申请表不通过，提交不通过原因并更新状态为6
	 * @param liveid
	 * @return
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoUserCommitNoPassByLiveID(int liveid, String memo) throws BusinessException;
	
	/**
	 * 更新T+0贷款申请记录的状态为7(放款初审，结算账户已变更)
	 * 并新增贷款申请最终记录
	 * @param liveid
	 * @param materials
	 * 
	 * used in OperatorUserController
	 * @throws BusinessException
	 */
	public int updateT0LoanLiveInfoAccChangePassAndCreateFinalInfo(int liveid, String materials) throws BusinessException;

	/**
	 * 更新Tx贷款申请记录的状态为2(已开通金融户)
	 * @throws BusinessException
	 */
	public int updateTxLoanLiveInfoAndCreateFinanceAccount(String operatetype, int liveid, int idOfTbMerchantUserOfCreditor, String pagets)
			throws BusinessException;
	
	/**
	 * 更新Tx贷款申请记录的状态为3(申请成功，已设置金融户)
	 * 并新增贷款申请最终记录
	 * used in OperatorUserController
	 * @throws BusinessException
	 */
	public int updateTxLoanLiveInfoAndSetFinanceAccount(String operatetype, int liveid, String financeAccount, String pagets)
			throws BusinessException;
	
	/**
	 * 查询后台管理员代办任务列表
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanTodoTaskVO> queryAdminUserTodoTaskList() throws BusinessException;
	
	/**
	 * 查询保理员代办任务列表
	 * @return
	 * @throws BusinessException
	 */
	public List<TbT0LoanTodoTaskVO> queryOperatorTodoTaskList() throws BusinessException;
	
	/**
	 * 根据相关参数生成账户变更申请表
	 * @param mhtno
	 * @param targetPDFFileFolder
	 * @return
	 * @throws BusinessException
	 */
	public String generateAccountChangeApplyFile(String mhtno, String finAccBankNo, String targetPDFFileFolder) throws BusinessException;
		
	/**
	 * Tx业务申请拒绝
	 * @return
	 * @throws BusinessException
	 */
	public int updateTxLoanLiveInfoApplyNoPassByLiveID(String operatetype, int liveid,
			String memo, String pagets) throws BusinessException;
}
